﻿
Position = {
    PositionUpdatePopUpId: '',
    CurrentRow: null,
    OnAddPositionClick: function () {
        $('#btnAddPosition').live("click", function (e) {
            e.preventDefault();
            Position.PositionUpdatePopUpId = $(this).attr("id");
            PopUpDialog.UrlDialog("Position", 420, 480, true, "../PopupBoxes/PositionDialogBox.aspx?id=0", $(this).attr("id"));
        });
    },
    OnUpdatePositionClick: function () {
        $('table#Positiontbl .btnUdpate').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("data-id");
            Position.CurrentRow = $(this).closest("tr");
            Position.PositionUpdatePopUpId = id;

            PopUpDialog.UrlDialog("Position", 420, 480, true, "../PopupBoxes/PositionDialogBox.aspx?id=" + id, id);
        });
    },
    OnDeletePositionClick: function () {
        $('table#Positiontbl .btnDelete').live("click", function (e) {
            e.preventDefault();
            if (confirm('Are you sure you want to delete item?')) {
                var id = $(this).attr("data-id");
                var json = JSON.stringify({ Id: id });
                Position.CurrentRow = $(this).closest("tr");
                $.ajax({
                    type: "POST",
                    url: "../Webservices/EmployeeWebService.asmx/DeletePosition",
                    data: json,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var response = eval('(' + data.d + ')');
                        if (response.Success) {
                            Position.CurrentRow.remove();
                        }
                    }
                });

            }
        });
    },
    SetRowData: function (Obj) {
        if (Obj.IsAdded) {
            location.reload(true);
        }
        var id = Obj.PositionItem.Id;
        var code = Obj.PositionItem.Code;
        var description = Obj.PositionItem.Description;
        var incentive = Obj.PositionItem.Incentive;
        var retirement = Obj.PositionItem.Retirement;
        var uniformAllowance = Obj.PositionItem.UniformAllowance;

        Position.CurrentRow.find("td").eq(0).html(id);
        Position.CurrentRow.find("td").eq(1).html(code);
        Position.CurrentRow.find("td").eq(2).html(description);
        Position.CurrentRow.find("td").eq(3).html(incentive);
        Position.CurrentRow.find("td").eq(4).html(retirement);
        Position.CurrentRow.find("td").eq(5).html(uniformAllowance);
    }
}

$(document).ready(function () {
    Position.OnAddPositionClick();
    Position.OnUpdatePositionClick();
    Position.OnDeletePositionClick();
});